import { defineStore } from 'pinia';

// SAIL-0001 存放路由信息
const routeStore = defineStore({
  id: 'router',
  state: () => ({
    history: [], // 存储路由历史记录（对象格式：{ path: string, params: object }）
  }),
  actions: {
    // 添加路由到历史记录
    addRoute(path, params = {}) {
      this.history.push({ path, params });
    },

    // 删除路由历史记录中的某一项
    deleteRoute(index) {
      if (index >= 0 && index < this.history.length) {
        this.history.splice(index, 1);
      }
    },

    // 清空路由历史记录
    clearHistory() {
      this.history = [];
    },
  },
  persist: {
    enabled: true,
    strategies: [
      {
        key: 'router-store',
      },
    ],
  },
});

export default routeStore;